Mod Operator
Returns the remainder of the division of two numbers.
Syntax
result= number1 Mod number2
Part | Description |
result | The remainder (as an Integer) of number1 divided by number2. |
number1 | Any number. |
number2 | Any number. |
The Mod operator divides number1 by number2 and returns the remainder as result. If number2 is zero, Mod returns number1.
The Mod operator operates on integers. If either number1 or number2 are non-integers, they are first truncated to integers. For example:
Examples
These examples use the Mod operator to divide two numbers and return the remainder.
Dim r As Integer
r=10 Mod 3 //Returns 1
r=2 Mod 4 //Returns 2
r=9.3 Mod 2.75 //Returns 1
r=4.5 Mod 1 //Returns 0
r=25 Mod 5 //Returns 0
r=10 Mod 3 //Returns 1
r=2 Mod 4 //Returns 2
r=9.3 Mod 2.75 //Returns 1
r=4.5 Mod 1 //Returns 0
r=25 Mod 5 //Returns 0
See Also
/, \ operators; Operator_Modulo function.